/**
 * 
 */
package kr.co.insoft.auth.mapper.codec;

import kr.co.insoft.auth.mapper.initialize.InitializeTableMapper;
import kr.co.insoft.auth.model.initialize.InitializeTableModel;
import kr.co.insoft.auth.service.initalize.InitializeTableService;
import kr.co.insoft.framework.mybatis.Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Mapper
public interface WeeklyCodecKeyMapper extends InitializeTableMapper {

	@Select("SELECT `codeckey` FROM `"
			+ InitializeTableService.CODEC_SALT_TABLE + "` WHERE `seq`='1'")
	public String getSalt() throws Exception;

	@Update("INSERT INTO `"
			+ InitializeTableService.CODEC_SALT_TABLE
			+ "`(`seq`, `codeckey`) VALUES('1', UUID()) ON DUPLICATE KEY UPDATE `codeckey`=UUID()")
	public void updateWeeklyCodecKey() throws Exception;

	@Override
	@Select("SELECT count(*) as `count` FROM information_schema.tables WHERE `TABLE_SCHEMA` = #{datasource} AND `TABLE_NAME` = #{tablename}")
	public Integer isExistTable(InitializeTableModel initializeTableModel)
			throws Exception;

	@Override
	@Insert("CREATE TABLE `"
			+ InitializeTableService.CODEC_SALT_TABLE
			+ "` (`seq` INT NOT NULL, `codeckey` VARCHAR(36) NULL, PRIMARY KEY (`seq`))")
	public void createTable() throws Exception;
}
